#ifndef FOODCONTROLLER_H
#define FOODCONTROLLER_H

#include <QNetworkAccessManager>
#include <QWidget>
#include <iostream>
#include "json/json.h"
#include <fstream>
#include <QObject>
#include <QString>
#include <QtNetwork>
#include <QJsonObject>
#include <QJsonDocument>

struct rFoodmessageInfo
{
    int code;
    QString data;
    QString message;
};
struct rFoodInfo
{
    int version;
    QString gmtCreate;
    QString gmtModified;
    int createUser;
    int createId;
    QString name;
    int type;
    int shelfLife;
    int unit;
    QString info;
    QString alias;
    QString pic;
};
struct sFoodInfo
{
    int userId;
    int foodId;
    QString name;
    QString type;
    QString unit;
    QString info;
    QString alias;
    QString pic;
    int shelfLife;
};

class FoodController : public QObject
{
    Q_OBJECT
public:
    explicit FoodController(QObject *parent = nullptr);
    QNetworkAccessManager *accessManager;
    QNetworkRequest request;
    QByteArray postData;
    QNetworkReply* reply;
    rFoodmessageInfo m_foodinfo;
    rFoodInfo r_foodinfo;
    QList<sFoodInfo> s_foodlist;
    void addFood(QString token,QString info,QString name,QString pic,QString shelfLife,int type,QString typeName,int unit,QString unitName);
    void updateFood(QString token,QString info,QString name,QString pic,QString shelfLife,int type,QString typeName,int unit,QString unitName,int createId,int createUser,QString gmtCreate,QString gmtModified,int version,QString alias);
    void infoFood(QString token,int createId);
    void searchDefaultFood(QString token,QString name,int index,int size);
    void searchCustomerFood(QString token,QString name,int index,int size);
private slots:
    void finishedSlot(QNetworkReply *reply);
signals:
    void foodcontrollersuccess();
    void infoFoodsuccess();
    void searchDefaultsuccess();
    void searchCustomersuccess();
};

#endif // FOODCONTROLLER_H
